package GUI;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class ChoosePanel extends JPanel
{
	private int choose,item;
	private String items[] = {"","","",""};
	private ImageIcon icon;
	
	public ChoosePanel()
	{
		choose = -1;
		item = 0;
		
		addMouseMotionListener
		(
			new MouseMotionAdapter()
			{
				public void mouseMoved(MouseEvent e)
				{
					if (item > 0)
					{
						choose = -1;
						
						if (item > 1 && e.getY() > 81 - 17 * item && e.getY() < 116 - 17 * item)
						{
							choose = 0;
						}
						
						if (item > 1 && e.getY() > 115 - 17 * item && e.getY() < 150 - 17 * item)
						{
							choose = 1;
						}
						
						if (item > 2 && e.getY() > 149 - 17 * item && e.getY() < 184 - 17 * item)
						{
							choose = 2;
						}
						
						if (item > 3 && e.getY() > 183 - 17 * item && e.getY() < 218 - 17 * item)
						{
							choose = 3;
						}
						
						repaint();
					}
				}
			}
		);
		
		setOpaque(false);
		setPreferredSize(new Dimension(752,154));
		setVisible(true);
	}
	
	public int getChoose()
	{
		return choose;
	}
	
	public void setText(String s[])
	{
		for (int i = 0;i < s.length;i++)
		{
			items[i] = s[i];
		}
		
		item = s.length;
		repaint();
	}
	
	public void clear()
	{
		for (int i = 0;i < 4;i++)
		{
			items[i] = "";
		}
		
		item = 0;
		choose = -1;
		repaint();
	}
	
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		if (item > 1)
		{
			icon = new ImageIcon("data\\system\\SEL" + item + "L.png");
			g.drawImage(icon.getImage(),0,60 - 15 * item,null);
		}
		
		g.setFont(new Font("Monospaced",Font.BOLD,20));
		
		for (int i = 0;i < item;i++)
		{
			if (choose == i)
			{
				g.setColor(Color.RED);
			}
			else
			{
				g.setColor(Color.BLACK);
			}
			
			g.drawString(items[i],377 - 10 * items[i].length(),30 * i - 15 * item + 97);
		}
		
		g.setColor(Color.WHITE);
		g.setFont(new Font("Monospaced",Font.BOLD,20));
		
		for (int i = 0;i < item;i++)
		{
			g.drawString(items[i],376 - 10 * items[i].length(),30 * i - 15 * item + 96);
		}
	}
}